/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.agtranscontinental.sisref.util;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.primefaces.context.RequestContext;

/**
 *
 * @author ericson
 */
public class Faces {

    public static final String getServerPath(String path) {
        return FacesContext.getCurrentInstance().getExternalContext().getRealPath(path);
    }

    public static final void addMessage(String mensaje, String componentId, FacesMessage.Severity severity) {
        FacesMessage fm = new FacesMessage(severity, mensaje, null);
        FacesContext.getCurrentInstance().addMessage(componentId, fm);
        updateComponent(componentId);
    }

    public static final void updateComponent(String componentId) {
        RequestContext.getCurrentInstance().update(componentId);
    }

    public static final void showDialog(String widgetVar) {
        RequestContext.getCurrentInstance().execute(widgetVar + ".show()");
    }

    public static final void hideDialog(String widgetVar) {
        RequestContext.getCurrentInstance().execute(widgetVar + ".hide()");
    }

    public static final void registerVariable(String variableName, Object object) {
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(variableName, object);
    }

    public static final void removeVariable(String variableName) {
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove(variableName);
    }

    public static final void getVariable(String variableName) {
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(variableName);
    }
}
